#region " LICENSE "
// DRILL - Dependency Resolution Interface Layer Library
// Copyright (c) 2008-2012 Wade A. Reynolds. All rights reserved.
// http://drill.codeplex.com/
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#endregion
namespace Drill.Core.Utilities.Extensions
{
	/// <summary>
	/// String extension methods that provide a convenient way of performing conversions.
	/// </summary>
    public static class StringExtensionMethods
    {
		/// <summary>
		/// Converts the string to a <see cref="bool"/> value.
		/// </summary>
		/// <param name="value">The string value.</param>
		/// <returns>
		/// A <see cref="bool"/> value parsed from the specified <paramref name="value"/> 
		/// or is the default value, <c>false</c>.
		/// </returns>
        public static bool ToBoolean(this string value)
        {
            return ToBoolean(value, false);
        }

		/// <summary>
		/// Converts the specified string value.
		/// </summary>
		/// <param name="value">The string representation of a boolean value.</param>
		/// <param name="defaultValue">
		/// The default value to be returned if the <paramref name="value"/> cannot be parsed.
		/// </param>
		/// <returns>
		/// An <see cref="bool"/> value that was either converted from the specified 
		/// <paramref name="value"/> of the specified <paramref name="defaultValue"/>.
		/// </returns>
        public static bool ToBoolean(this string value, bool defaultValue)
        {
            return StringToBooleanConverter.Convert(value, defaultValue);
        }

		/// <summary>
		/// Converts the string to an <see cref="int"/> value.
		/// </summary>
		/// <param name="value">The string value.</param>
		/// <returns>
		/// An <see cref="int"/> value parsed from the specified <paramref name="value"/> 
		/// or is the default value, <c>-1</c>.
		/// </returns>
        public static int ToInt32(this string value)
        {
            return ToInt32(value, -1);
        }

		/// <summary>
		/// Converts the specified string value.
		/// </summary>
		/// <param name="value">The string representation of a 32-bit integer value.</param>
		/// <param name="defaultValue">
		/// The default value to be returned if the <paramref name="value"/> cannot be parsed.
		/// </param>
		/// <returns>
		/// An <see cref="int"/> value that was either converted from the specified 
		/// <paramref name="value"/> of the specified <paramref name="defaultValue"/>.
		/// </returns>
        public static int ToInt32(this string value, int defaultValue)
        {
            return StringToInt32Converter.Convert(value, defaultValue);
        }
    }
}